home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 April / SGI IRIX 6.5 Applications 2004 April.iso / dist / mozilla.idb / var / netscape / mozilla / chrome / messenger.jar.z / messenger.jar / content / messenger-smime / msgCompSecurityInfo.js < prev    next >
Text File  |  2003-11-11  |  8KB  |  292 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Mozilla Communicator.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Netscape Communications Corporation.
  18.  * Portions created by the Initial Developer are Copyright (C) 2002
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  25.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  *
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. var gListBox;
  38. var gViewButton;
  39. var gBundle;
  40.  
  41. var gEmailAddresses;
  42. var gCertStatusSummaries;
  43. var gCertIssuedInfos;
  44. var gCertExpiresInfos;
  45. var gCerts;
  46. var gCount;
  47.  
  48. var gSMimeContractID = "@mozilla.org/messenger-smime/smimejshelper;1";
  49. var gISMimeJSHelper = Components.interfaces.nsISMimeJSHelper;
  50. var gIX509Cert = Components.interfaces.nsIX509Cert;
  51. const nsICertificateDialogs = Components.interfaces.nsICertificateDialogs;
  52. const nsCertificateDialogs = "@mozilla.org/nsCertificateDialogs;1"
  53.  
  54. function getStatusExplanation(value)
  55. {
  56.   switch (value)
  57.   {
  58.     case gIX509Cert.VERIFIED_OK:
  59.       return gBundle.getString("StatusValid");
  60.  
  61.     case gIX509Cert.NOT_VERIFIED_UNKNOWN:
  62.     case gIX509Cert.INVALID_CA:
  63.     case gIX509Cert.USAGE_NOT_ALLOWED:
  64.       return gBundle.getString("StatusInvalid");
  65.  
  66.     case gIX509Cert.CERT_REVOKED:
  67.       return gBundle.getString("StatusRevoked");
  68.  
  69.     case gIX509Cert.CERT_EXPIRED:
  70.       return gBundle.getString("StatusExpired");
  71.  
  72.     case gIX509Cert.CERT_NOT_TRUSTED:
  73.     case gIX509Cert.ISSUER_NOT_TRUSTED:
  74.     case gIX509Cert.ISSUER_UNKNOWN:
  75.       return gBundle.getString("StatusUntrusted");
  76.   }
  77.  
  78.   return "";
  79. }
  80.  
  81. function onLoad()
  82. {
  83.   document.getElementById("cancel").setAttribute("collapsed", "true");
  84.  
  85.   var params = window.arguments[0];
  86.   if (!params)
  87.     return;
  88.  
  89.   var helper = Components.classes[gSMimeContractID].createInstance(gISMimeJSHelper);
  90.  
  91.   if (!helper)
  92.     return;
  93.  
  94.   gListBox = document.getElementById("infolist");
  95.   gViewButton = document.getElementById("viewCertButton");
  96.   gBundle = document.getElementById("bundle_smime_comp_info");
  97.  
  98.   gEmailAddresses = new Object();
  99.   gCertStatusSummaries = new Object();
  100.   gCertIssuedInfos = new Object();
  101.   gCertExpiresInfos = new Object();
  102.   gCerts = new Object();
  103.   gCount = new Object();
  104.   var canEncrypt = new Object();
  105.  
  106.   var allow_ldap_cert_fetching = false;
  107.  
  108.   try {  
  109.     if (params.compFields.securityInfo.requireEncryptMessage) {
  110.       allow_ldap_cert_fetching = true;
  111.     }
  112.   }
  113.   catch (e)
  114.   {
  115.   }
  116.  
  117.   while (true)
  118.   {
  119.     try
  120.     {
  121.       helper.getRecipientCertsInfo(
  122.         params.compFields,
  123.         gCount,
  124.         gEmailAddresses,
  125.         gCertStatusSummaries,
  126.         gCertIssuedInfos,
  127.         gCertExpiresInfos,
  128.         gCerts,
  129.         canEncrypt);
  130.     }
  131.     catch (e)
  132.     {
  133.       dump(e);
  134.       return;
  135.     }
  136.  
  137.     if (!allow_ldap_cert_fetching)
  138.       break;
  139.  
  140.     allow_ldap_cert_fetching = false;
  141.  
  142.     var missing = new Array();
  143.  
  144.     for (var j = gCount.value - 1; j >= 0; --j)
  145.     {
  146.       if (!gCerts.value[j])
  147.       {
  148.         missing[missing.length] = gEmailAddresses.value[j];
  149.       }
  150.     }
  151.  
  152.     if (missing.length > 0)
  153.     {
  154.       var prefService = 
  155.         Components.classes["@mozilla.org/preferences-service;1"]
  156.           .getService(Components.interfaces.nsIPrefService);
  157.       var sPrefs = prefService.getBranch(null);
  158.  
  159.       var autocompleteLdap = false;
  160.       autocompleteLdap = sPrefs.getBoolPref("ldap_2.autoComplete.useDirectory");
  161.  
  162.       if (autocompleteLdap)
  163.       {
  164.         var autocompleteDirectory = null;
  165.         autocompleteDirectory = sPrefs.getCharPref(
  166.           "ldap_2.autoComplete.directoryServer");
  167.  
  168.         if(params.currentIdentity.overrideGlobalPref) {
  169.           autocompleteDirectory = params.currentIdentity.directoryServer;
  170.         }
  171.  
  172.         if (autocompleteDirectory)
  173.         {
  174.           window.openDialog('chrome://messenger-smime/content/certFetchingStatus.xul',
  175.             '',
  176.             'chrome,resizable=1,modal=1,dialog=1', 
  177.             autocompleteDirectory,
  178.             missing
  179.           );
  180.         }
  181.       }
  182.     }
  183.   }
  184.  
  185.   if (gBundle)
  186.   {
  187.     var yes_string = gBundle.getString("StatusYes");
  188.     var no_string = gBundle.getString("StatusNo");
  189.     var not_possible_string = gBundle.getString("StatusNotPossible");
  190.  
  191.     var signed_element = document.getElementById("signed");
  192.     var encrypted_element = document.getElementById("encrypted");
  193.     
  194.     if (params.smFields.requireEncryptMessage)
  195.     {
  196.       if (params.isEncryptionCertAvailable && canEncrypt.value)
  197.       {
  198.         encrypted_element.value = yes_string;
  199.       }
  200.       else
  201.       {
  202.         encrypted_element.value = not_possible_string;
  203.       }
  204.     }
  205.     else
  206.     {
  207.       encrypted_element.value = no_string;
  208.     }
  209.     
  210.     if (params.smFields.signMessage)
  211.     {
  212.       if (params.isSigningCertAvailable)
  213.       {
  214.         signed_element.value = yes_string;
  215.       }
  216.       else
  217.       {
  218.         signed_element.value = not_possible_string;
  219.       }
  220.     }
  221.     else
  222.     {
  223.       signed_element.value = no_string;
  224.     }
  225.   }
  226.  
  227.   var imax = gCount.value;
  228.   
  229.   for (var i = 0; i < imax; ++i)
  230.   {
  231.     var listitem  = document.createElement("listitem");
  232.  
  233.     listitem.appendChild(createCell(gEmailAddresses.value[i]));
  234.     
  235.     if (!gCerts.value[i])
  236.     {
  237.       listitem.appendChild(createCell(gBundle.getString("StatusNotFound")));
  238.     }
  239.     else
  240.     {
  241.       listitem.appendChild(createCell(getStatusExplanation(gCertStatusSummaries.value[i])));
  242.       listitem.appendChild(createCell(gCertIssuedInfos.value[i]));
  243.       listitem.appendChild(createCell(gCertExpiresInfos.value[i]));
  244.     }
  245.  
  246.     gListBox.appendChild(listitem);
  247.   }
  248. }
  249.  
  250. function onSelectionChange(event)
  251. {
  252.   if (gListBox.selectedItems.length <= 0)
  253.   {
  254.     gViewButton.setAttribute("disabled", "true");
  255.   }
  256.   else
  257.   {
  258.     gViewButton.removeAttribute("disabled");
  259.   }
  260. }
  261.  
  262. function viewCertHelper(parent, cert) {
  263.   var cd = Components.classes[nsCertificateDialogs].getService(nsICertificateDialogs);
  264.   cd.viewCert(parent, cert);
  265. }
  266.  
  267. function viewSelectedCert()
  268. {
  269.   if (gListBox.selectedItems.length > 0)
  270.   {
  271.     var selected = gListBox.selectedIndex;
  272.     var cert = gCerts.value[selected];
  273.     if (cert)
  274.     {
  275.       viewCertHelper(window, cert);
  276.     }
  277.   }
  278. }
  279.  
  280. function doHelpButton()
  281. {
  282.   openHelp('compose_security');
  283. }
  284.  
  285. function createCell(label)
  286. {
  287.   var cell = document.createElement("listcell");
  288.   cell.setAttribute("label", label)
  289.   return cell;
  290. }
  291.  
  292.